<template>
    <el-row class="enterList">
        <el-table :data="tableData" style="width: 100%">
            <el-table-column label="#" width="50" v-if="close">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleDelete(scope.$index)">
                        <i class="fa fa-close fa-lg"></i>
                    </el-button>
                </template>
            </el-table-column>
            <el-table-column prop="id" label="客户编号" width="180">
            </el-table-column>
            <el-table-column prop="name" label="客户名称" width="200">
            </el-table-column>
            <el-table-column prop="type" label="类型" width="80">
            </el-table-column>
            <el-table-column prop="level" label="等级" width="80">
            </el-table-column>
            <el-table-column prop="address" label="地址">
            </el-table-column>
        </el-table>
    </el-row>
</template>
<script>
import "./index.scss";

export default {
  data() {
    return {
      tableData: []
    };
  },
  props: {
    value: {
      type: Array,
      default: []
    },
    close: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    handleDelete: function(index) {
      this.tableData.splice(index, 1);
      this.updateValue();
    },
    updateValue: function() {
      let valueArr = [];
      if (this.tableData.length != 0) {
        for (let index = 0; index < this.tableData.length; index++) {
          const element = this.tableData[index];
          valueArr.push(element.id);
        }
      }
      this.$emit("input", valueArr);
    }
  },
  watch: {},
  mounted: function() {},
  created: function() {
    this.tableData = [
      {
        id: "1",
        name: "客户1",
        type: "大酒楼",
        level: "1",
        address: "大金钟路63号"
      },
      {
        id: "2",
        name: "客户2",
        type: "便利店",
        level: "2",
        address: "大金钟路64号"
      },
      {
        id: "3",
        name: "客户3",
        type: "大酒楼",
        level: "5",
        address: "大金钟路63号"
      },
      {
        id: "4",
        name: "客户4",
        type: "便利店",
        level: "4",
        address: "大金钟路64号"
      }
    ];
  },
  beforeDestroy: function() {}
};
</script>